﻿namespace ARchGL.Platform.Authorization.Accounts.Dto
{
    public class IsTenantAvailableOutput
    {
        public TenantAvailabilityState State { get; set; }

        public int? TenantId { get; set; }

        /// <summary>
        /// API服务地址
        /// </summary>
        public string ServerRootAddress { get; set; }

        /// <summary>
        /// 文件服务地址
        /// </summary>
        public string FileServerRootAddress { get; set; }

        /// <summary>
        /// 认证服务地址
        /// </summary>
        public string IdentityRootAddress { get; set; }

        public IsTenantAvailableOutput()
        {
            
        }

        public IsTenantAvailableOutput(TenantAvailabilityState state, int? tenantId = null)
        {
            State = state;
            TenantId = tenantId;
        }

        public IsTenantAvailableOutput(TenantAvailabilityState state, int? tenantId, string serverRootAddress)
        {
            State = state;
            TenantId = tenantId;
            ServerRootAddress = CheckLastChar(serverRootAddress);
        }

        /// <summary>
        /// 检查最后是否包含斜杠，并根据参数设置是否需要
        /// </summary>
        /// <param name="url">Url</param>
        /// <param name="type">是否需要末尾斜杠，默认不需要 false</param>
        /// <returns></returns>
        public string CheckLastChar(string url, bool type = false)
        {
            var length = url.LastIndexOf('/');
            if (type && length != url.Length - 1)//需要字斜杠，且为未包含
                return url + "/";
            else if (!type && length == url.Length - 1)//不需要斜杠，且已存在
                return url.Substring(0, url.Length - 1);

            return url;
        }
    }
}